from openpyxl import Workbook
from openpyxl.chart import Reference, Series, BarChart3D

wb = Workbook()
ws = wb.active

rows = [
    (None, 2021, 2022),
    ("平板", 10, 15),
    ("手机", 15, 20),
    ("电脑", 20, 25),
]
for row in rows:
    ws.append(row)

chart = BarChart3D()
chart.title = "3D图表"
data = Reference(ws, min_col=2, min_row=1, max_col=3, max_row=4)
labels = Reference(ws, min_col=1, min_row=2, max_row=4)
chart.add_data(data, titles_from_data=True)
ws.add_chart(chart, "E5")
chart.set_categories(labels)

wb.save("3dchart.xlsx")